<template>
  <!-- 列表页面 -->
  <div class="tableSample" v-if="!showAdd && !showEdit">
    <div class="header">
      <div class="header-left">
        <p class="title">
          店面排行
        </p>
      </div>
      <div class="header-right">
        <lin-search @query="onQueryChange" placeholder="请输入名称" />
        <lin-date-picker @dateChange="handleDateChange" ref="searchDate" class="date" style="margin-left: 20px">
        </lin-date-picker>
      </div>
    </div>
    <!-- 表格 -->
    <lin-table
            border
            :tableColumn="tableColumn"
            :tableData="tableData"
            :operate="operate"
            @handleList="handleList"
            v-loading="loading"
    ></lin-table>
    <!-- 分页 -->
    <div class="pagination" v-if="total_nums > 0">
      <el-pagination
              @current-change="handleCurrentChange"
              :background="true"
              :page-size="pageCount"
              :current-page="currentPage"
              v-if="refreshPagination"
              layout="total, prev, pager, next, jumper"
              :operate="operate"
              :total="total_nums"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import rank from '@/models/rank'
import LinSearch from '@/components/base/search/lin-search'
import LinTable from '@/components/base/table/lin-table'
import LinDatePicker from '@/components/base/date-picker/lin-date-picker'

export default {
  components: {
    LinSearch,
    LinTable,
    LinDatePicker,
  },
  data() {
    return {
      tableColumn: [
        {
          prop: 'name',
          label: '店面名称',
        },
        {
          prop: 'rank.sale',
          label: '销售额',
          width: 150,
          sortable: true,
        },
        {
          prop: 'rank.shou_xu',
          label: '手续费',
          width: 150,
          sortable: true,
        },
        {
          prop: 'rank.user_money',
          label: '顾客佣金',
          width: 150,
          sortable: true,
        },
        {
          prop: 'rank.store_money',
          label: '员工收入',
          width: 150,
          sortable: true,
        },
        // {
        //   prop: 'rank.invite_money',
        //   label: '总返佣数',
        //   width: 150,
        //   sortable: true,
        // },
        {
          prop: 'rank.fission',
          label: '裂变数',
          sortable: true,
        },
        {
          prop: 'rank.volume',
          label: '成交量',
          sortable: true,
        },
        {
          prop: 'rank.new_user',
          label: '新用户数量',
          sortable: true,
        },
      ],
      tableData: [],
      operate: [],
      loading: false,
      showAdd: false,
      showEdit: false,
      orderSort: 0,
      StoreId: 0,
      search: {
        name: '',
        start_time: '',
        end_time: '',
      },
      // 分页相关
      refreshPagination: true, // 页数增加的时候，因为缓存的缘故，需要刷新Pagination组件
      currentPage: 1, // 默认获取第一页的数据
      pageCount: 10, // 每页10条数据
      total_nums: 0, // 分组内的总数
      dialogImageUrl: '',
      dialogVisible: false,
    }
  },
  computed: {},
  created() {
    this._getTableData(this.currentPage, this.pageCount)
  },
  methods: {
    handleList(val) {
      this.dialogVisible = true
      this.dialogImageUrl = val.row.store_url
    },
    editClose() {
      this.showEdit = false
      this.loading = true
      this._getTableData(this.currentPage, this.pageCount)
    },
    // 切换分页
    async handleCurrentChange(val) {
      this.currentPage = val
      this.loading = true
      this._getTableData(this.currentPage, this.pageCount)
    },
    // 搜索姓名
    onQueryChange(query) {
      this.search.name = query.trim()
      if (!query) {
        this._getTableData(1, 10)
        return
      }
      this.loading = true
      this.currentPage = 1
      this._getTableData(this.currentPage, this.pageCount)
    },
    handleDateChange(date) {
      if (date) {
        // eslint-disable-next-line prefer-destructuring
        this.search.start_time = date[0]
        // eslint-disable-next-line prefer-destructuring
        this.search.end_time = date[1]
      } else {
        this.search.start_time = ''
        this.search.end_time = ''
      }
      this.loading = true
      this._getTableData(this.currentPage, this.pageCount)
    },
    // 获取数据
    async _getTableData(start, count) {
      const res = await rank.getStoreRank({
        page: start,
        limit: count,
        name: this.search.name,
        start_time: this.search.start_time,
        end_time: this.search.end_time,
      })
      this.tableData = res
      this.$nextTick(() => {
        this.loading = false
      })
    },
  },
}
</script>

<style lang="scss" scoped>
  .tableSample {
    padding: 0 0 30px;

    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 30px;
      border-bottom: 1px solid #dae1ed;

      .header-left {
        float: left;

        .title {
          height: 59px;
          line-height: 59px;
          color: $parent-title-color;
          font-size: 16px;
          font-weight: 500;
        }
      }

      .header-right {
        float: right;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .table-main {
      padding: 0 30px;
      margin-top: 30px;
    }

    .top-operate {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
      margin-top: 30px;
    }

    .sort-input {
      width: 50px;
      background: none;
      justify-content: space-around;
    }

    .table-edit {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      .content {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .cell-icon {
        cursor: pointer;
        color: #3963bc;
        font-size: 16px;
      }

      .cell-icon-edit {
        display: flex;
        margin-left: 20px;
        width: 50px;
        justify-content: space-between;

        .cell-cancel {
          cursor: pointer;
          color: #3963bc;
          font-size: 16px;
        }

        .cell-save {
          cursor: pointer;
          color: #3963bc;
          font-size: 16px;
          margin-right: -20px;
        }
      }
    }

    .m-20 {
      margin-bottom: 10px;
      margin-top: 5px;
    }

    .summary {
      display: flex;
      justify-content: flex-start;
      flex-direction: row;

      img {
        width: 135px;
        height: 200px;
      }

      .demo-table-expand {
        font-size: 0;
        margin-left: 30px;
        display: flex;
        flex-direction: column;

        label {
          width: 90px;
          color: #99a9bf;
        }

        .el-form-item {
          margin-right: 0;
          margin-bottom: 0;
          display: flex;
          flex-direction: row;
        }
      }
    }

    .pagination {
      display: flex;
      justify-content: flex-end;
      margin: 20px;
    }
  }
  // dialog
  .tableSample /deep/ .el-dialog__footer {
    text-align: left;
    padding-left: 30px;
  }

  .tableSample /deep/ .el-dialog__header {
    padding-left: 30px;
  }

  .tableSample /deep/ .el-dialog__body {
    padding: 30px;
  }
</style>
